<?php

/*
 * Action - Attack 5$
 *
 * Trash this. Each other player with 5 or more cards in hand reveals his hand and discards a card that you choose.
 * Gain two Spoils from the Spoils pile.
 */

class Pillage extends Card implements iAction, iKingdom, iDarkAges, iAttack {

    public function __construct() {
        parent::__construct("Pillage", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash this. Each other player with 5 or more cards in hand reveals his hand and discards a card that you choose.",
            "Gain two Spoils from the Spoils pile.");
    }

    public function play(Game $game, $isRealCard) {
        $game->attack($this);

        $game->moveCardFromPileToPile($this, PlayArea, Trash);
        ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($this), "trashes " . ScreenDisplay::$LMSG);

        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize >= 5) {

                ScreenDisplay::addScreenMessage($game, true, "reveal" . nicePrint($playHandOther), " reveals " . ScreenDisplay::$LMSG, $name);

                $playHandOther = getUniqueCards($playHandOther);
                $card = null;
                if (sizeof($playHandOther > 0)) {
                    $output = MySocket::GetUserReply($game, Input_ChooseOne, $playHandOther, 1, 1, null, "Choose card to discard for " . $name);
                    $card = $game->moveCardFromPileToPile($output[0], PlayHand, DiscardPile, $name);
                }
                else {
                    $card = $playHandOther[0];
                }
                ScreenDisplay::addScreenMessage($game, false, " and forced to discard " . nicePrint($card), " and forced to discard " . ScreenDisplay::$LMSG, $name);
            } else {
                ScreenDisplay::addScreenMessage($game, true, "reveal nothing becauseyou has less than 5 cards", "reveals nothing because he has less than 5 cards", $name);
            }
        }

        $s1 = $game->moveCardFromPileToPile(null, Spoils, DiscardPile);
        $s2 = $game->moveCardFromPileToPile(null, Spoils, DiscardPile);

        $spoils = array();
        if ($s1)
            $spoils[] = $s1;
        if ($s2)
            $spoils[] = $s2;

        ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($spoils), " gains" . ScreenDisplay::$LMSG);
        $game->cardActionFinished();
        return true;
    }

    public function boardSetup(Game $game) {
        $game->addSpoils();
        return true;
    }

}

?>